Skip to content

枚举摄像头 - EnumCameras ​

函数简介 ​

枚举本机摄像头,以及驱动报告的像素规格。不占用设备,适合在 OpenCameraEx 或 display="camera" 绑定之前选择设备和分辨率。

formats[].width / formats[].height 就是该设备支持的像素大小。

接口名称 ​

EnumCameras

DLL调用 ​

c
int64_t EnumCameras(int64_t instance);

参数说明 ​

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。

返回 JSON ​

成功时为 JSON 数组。每项字段:

字段类型说明
index整数设备索引,对应 OpenCamera 的 deviceIndex,以及 SetConfig 的 CameraIndex。
name字符串设备友好名。按名称打开或绑定时写入 OpenCameraEx / CameraName。
path字符串设备路径;部分后端可能为空。
backend字符串枚举后端,如 DSHOW、MSMF、DEFAULT。
formats数组驱动报告的可选规格。每项含 width、height、fps、fourcc。
json
[
  {
    "index": 0,
    "name": "USB Camera",
    "path": "",
    "backend": "DSHOW",
    "formats": [
      { "width": 1920, "height": 1080, "fps": 30.0, "fourcc": "MJPG" },
      { "width": 1280, "height": 720, "fps": 30.0, "fourcc": "YUY2" }
    ]
  }
]

Windows 下优先走 DirectShow 枚举。DirectShow 枚举为空时,会按索引探测前若干个设备,此时 formats 可能只有当前默认规格一项。

示例 ​

SDK 调用 ​

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
std::string cameras = ola.EnumCameras();
csharp
using OLAPlug;

var ola = new OLAPlugServer();
string cameras = ola.EnumCameras();
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
cameras = ola.EnumCameras()
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
String cameras = ola.EnumCameras();
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
cameras := ola.EnumCameras()
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let cameras = ola.enum_cameras();
cpp
var ola = com("OlaPlug.OlaSoft")
var cameras = ola.EnumCameras()
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
cameras = ola.EnumCameras()
text
.局部变量 ola, OLAPlug
ola.创建 ()
cameras = ola.EnumCameras()
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var cameras = ola.EnumCameras();
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
文本型 cameras = ola.EnumCameras()
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
std::string cameras = ola.EnumCameras();

原生 DLL 调用 ​

cpp
int64_t ptr = EnumCameras(instance);
// 读取 JSON 后调用 FreeStringPtr(ptr)
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long EnumCameras(long ola);

long ptr = EnumCameras(instance);
python
from ctypes import CDLL, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.EnumCameras.restype = c_int64
ptr = ola.EnumCameras(instance)

返回值 ​

返回值说明
(返回值)字符串指针,内容为摄像头 JSON 数组。失败返回 0。返回的字符串指针需要调用 FreeStringPtr 释放内存。

注意事项 ​

项目说明
绑定前读取本接口不打开设备。绑定后的实际像素大小用 GetBindCameraInfo 或 GetClientSize。
规格是驱动报告值formats 是驱动声明的可选规格,设备最终协商结果可能不同。
无设备本机没有摄像头时返回 JSON 数组 [](指针非 0)。接口失败才返回 0。